home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / ld / ld.info-1 < prev    next >
Encoding:
GNU Info File  |  1996-07-15  |  46.4 KB  |  1,150 lines

  1. This is Info file ld.info, produced by Makeinfo-1.55 from the input
  2. file ./ld.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Ld: (ld).                       The GNU linker.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the GNU linker LD.
  9.  
  10.    Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation,
  11. Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the entire resulting derived work is distributed under the terms
  20. of a permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions.
  25.  
  26. 
  27. File: ld.info,  Node: Top,  Next: Overview,  Prev: (DIR),  Up: (DIR)
  28.  
  29. Using ld
  30. ********
  31.  
  32.    This file documents the GNU linker ld.
  33.  
  34. * Menu:
  35.  
  36. * Overview::                    Overview
  37. * Invocation::                  Invocation
  38. * Commands::                    Command Language
  39.  
  40. * Machine Dependent::           Machine Dependent Features
  41.  
  42. * BFD::                         BFD
  43.  
  44. * MRI::                         MRI Compatible Script Files
  45. * Index::                       Index
  46.  
  47. 
  48. File: ld.info,  Node: Overview,  Next: Invocation,  Prev: Top,  Up: Top
  49.  
  50. Overview
  51. ********
  52.  
  53.    `ld' combines a number of object and archive files, relocates their
  54. data and ties up symbol references. Usually the last step in compiling
  55. a program is to run `ld'.
  56.  
  57.    `ld' accepts Linker Command Language files written in a superset of
  58. AT&T's Link Editor Command Language syntax, to provide explicit and
  59. total control over the linking process.
  60.  
  61.    This version of `ld' uses the general purpose BFD libraries to
  62. operate on object files. This allows `ld' to read, combine, and write
  63. object files in many different formats--for example, COFF or `a.out'.
  64. Different formats may be linked together to produce any available kind
  65. of object file.  *Note BFD::, for more information.
  66.  
  67.    Aside from its flexibility, the GNU linker is more helpful than other
  68. linkers in providing diagnostic information.  Many linkers abandon
  69. execution immediately upon encountering an error; whenever possible,
  70. `ld' continues executing, allowing you to identify other errors (or, in
  71. some cases, to get an output file in spite of the error).
  72.  
  73. 
  74. File: ld.info,  Node: Invocation,  Next: Commands,  Prev: Overview,  Up: Top
  75.  
  76. Invocation
  77. **********
  78.  
  79.    The GNU linker `ld' is meant to cover a broad range of situations,
  80. and to be as compatible as possible with other linkers.  As a result,
  81. you have many choices to control its behavior.
  82.  
  83. * Menu:
  84.  
  85. * Options::                     Command Line Options
  86. * Environment::                 Environment Variables
  87.  
  88. 
  89. File: ld.info,  Node: Options,  Next: Environment,  Up: Invocation
  90.  
  91. Command Line Options
  92. ====================
  93.  
  94.    The linker supports a plethora of command-line options, but in actual
  95. practice few of them are used in any particular context.  For instance,
  96. a frequent use of `ld' is to link standard Unix object files on a
  97. standard, supported Unix system.  On such a system, to link a file
  98. `hello.o':
  99.  
  100.      ld -o OUTPUT /lib/crt0.o hello.o -lc
  101.  
  102.    This tells `ld' to produce a file called OUTPUT as the result of
  103. linking the file `/lib/crt0.o' with `hello.o' and the library `libc.a',
  104. which will come from the standard search directories.  (See the
  105. discussion of the `-l' option below.)
  106.  
  107.    The command-line options to `ld' may be specified in any order, and
  108. may be repeated at will.  Repeating most options with a different
  109. argument will either have no further effect, or override prior
  110. occurrences (those further to the left on the command line) of that
  111. option.  Options which may be meaningfully specified more than once are
  112. noted in the descriptions below.
  113.  
  114.    Non-option arguments are objects files which are to be linked
  115. together.  They may follow, precede, or be mixed in with command-line
  116. options, except that an object file argument may not be placed between
  117. an option and its argument.
  118.  
  119.    Usually the linker is invoked with at least one object file, but you
  120. can specify other forms of binary input files using `-l', `-R', and the
  121. script command language.  If *no* binary input files at all are
  122. specified, the linker does not produce any output, and issues the
  123. message `No input files'.
  124.  
  125.    If the linker can not recognize the format of an object file, it will
  126. assume that it is a linker script.  A script specified in this way
  127. augments the main linker script used for the link (either the default
  128. linker script or the one specified by using `-T').  This feature
  129. permits the linker to link against a file which appears to be an object
  130. or an archive, but actually merely defines some symbol values, or uses
  131. `INPUT' or `GROUP' to load other objects.  *Note Commands::.
  132.  
  133.    For options whose names are a single letter, option arguments must
  134. either follow the option letter without intervening whitespace, or be
  135. given as separate arguments immediately following the option that
  136. requires them.
  137.  
  138.    For options whose names are multiple letters, either one dash or two
  139. can precede the option name; for example, `--oformat' and `-oformat'
  140. are equivalent.  Arguments to multiple-letter options must either be
  141. separated from the option name by an equals sign, or be given as
  142. separate arguments immediately following the option that requires them.
  143. For example, `--oformat srec' and `--oformat=srec' are equivalent.
  144. Unique abbreviations of the names of multiple-letter options are
  145. accepted.
  146.  
  147. `-aKEYWORD'
  148.      This option is supported for HP/UX compatibility.  The KEYWORD
  149.      argument must be one of the strings `archive', `shared', or
  150.      `default'.  `-aarchive' is functionally equivalent to `-Bstatic',
  151.      and the other two keywords are functionally equivalent to
  152.      `-Bdynamic'.  This option may be used any number of times.
  153.  
  154. `-AARCHITECTURE'
  155. `--architecture=ARCHITECTURE'
  156.      In the current release of `ld', this option is useful only for the
  157.      Intel 960 family of architectures.  In that `ld' configuration, the
  158.      ARCHITECTURE argument identifies the particular architecture in
  159.      the 960 family, enabling some safeguards and modifying the
  160.      archive-library search path.  *Note `ld' and the Intel 960 family:
  161.      i960, for details.
  162.  
  163.      Future releases of `ld' may support similar functionality for
  164.      other architecture families.
  165.  
  166. `-b INPUT-FORMAT'
  167. `--format=INPUT-FORMAT'
  168.      `ld' may be configured to support more than one kind of object
  169.      file.  If your `ld' is configured this way, you can use the `-b'
  170.      option to specify the binary format for input object files that
  171.      follow this option on the command line.  Even when `ld' is
  172.      configured to support alternative object formats, you don't
  173.      usually need to specify this, as `ld' should be configured to
  174.      expect as a default input format the most usual format on each
  175.      machine.  INPUT-FORMAT is a text string, the name of a particular
  176.      format supported by the BFD libraries.  (You can list the
  177.      available binary formats with `objdump -i'.) *Note BFD::.
  178.  
  179.      You may want to use this option if you are linking files with an
  180.      unusual binary format.  You can also use `-b' to switch formats
  181.      explicitly (when linking object files of different formats), by
  182.      including `-b INPUT-FORMAT' before each group of object files in a
  183.      particular format.
  184.  
  185.      The default format is taken from the environment variable
  186.      `GNUTARGET'.  *Note Environment::.  You can also define the input
  187.      format from a script, using the command `TARGET'; see *Note Option
  188.      Commands::.
  189.  
  190. `-c MRI-COMMANDFILE'
  191. `--mri-script=MRI-COMMANDFILE'
  192.      For compatibility with linkers produced by MRI, `ld' accepts script
  193.      files written in an alternate, restricted command language,
  194.      described in *Note MRI Compatible Script Files: MRI.  Introduce
  195.      MRI script files with the option `-c'; use the `-T' option to run
  196.      linker scripts written in the general-purpose `ld' scripting
  197.      language.  If MRI-CMDFILE does not exist, `ld' looks for it in the
  198.      directories specified by any `-L' options.
  199.  
  200. `-d'
  201. `-dc'
  202. `-dp'
  203.      These three options are equivalent; multiple forms are supported
  204.      for compatibility with other linkers.  They assign space to common
  205.      symbols even if a relocatable output file is specified (with
  206.      `-r').  The script command `FORCE_COMMON_ALLOCATION' has the same
  207.      effect.  *Note Option Commands::.
  208.  
  209. `-e ENTRY'
  210. `--entry=ENTRY'
  211.      Use ENTRY as the explicit symbol for beginning execution of your
  212.      program, rather than the default entry point. *Note Entry Point::,
  213.      for a discussion of defaults and other ways of specifying the
  214.      entry point.
  215.  
  216. `-E'
  217. `-export-dynamic'
  218.      When creating a dynamically linked executable, add all symbols to
  219.      the dynamic symbol table.  Normally, the dynamic symbol table
  220.      contains only symbols which are used by a dynamic object.  This
  221.      option is needed for some uses of `dlopen'.
  222.  
  223. `-F'
  224. `-FFORMAT'
  225.      Ignored.  Some older linkers used this option throughout a
  226.      compilation toolchain for specifying object-file format for both
  227.      input and output object files.  The mechanisms `ld' uses for this
  228.      purpose (the `-b' or `-format' options for input files, `-oformat'
  229.      option or the `TARGET' command in linker scripts for output files,
  230.      the `GNUTARGET' environment variable) are more flexible, but `ld'
  231.      accepts the `-F' option for compatibility with scripts written to
  232.      call the old linker.
  233.  
  234. `--force-exe-suffix'
  235.      Make sure that an output file has a .exe suffix.
  236.  
  237.      If a successfully built fully linked output file does not have a
  238.      `.exe' or `.dll' suffix, this option forces the linker to copy the
  239.      output file to one of the same name with a `.exe' suffix. This
  240.      option is useful when using unmodified Unix makefiles on a
  241.      Microsoft Windows host, since some versions of Windows won't run
  242.      an image unless it ends in a `.exe' suffix.
  243.  
  244. `-g'
  245.      Ignored.  Provided for compatibility with other tools.
  246.  
  247. `-GVALUE'
  248. `--gpsize=VALUE'
  249.      Set the maximum size of objects to be optimized using the GP
  250.      register to SIZE.  This is only meaningful for object file formats
  251.      such as MIPS ECOFF which supports putting large and small objects
  252.      into different sections.  This is ignored for other object file
  253.      formats.
  254.  
  255. `-hNAME'
  256. `-soname=NAME'
  257.      When creating an ELF shared object, set the internal DT_SONAME
  258.      field to the specified name.  When an executable is linked with a
  259.      shared object which has a DT_SONAME field, then when the
  260.      executable is run the dynamic linker will attempt to load the
  261.      shared object specified by the DT_SONAME field rather than the
  262.      using the file name given to the linker.
  263.  
  264. `-i'
  265.      Perform an incremental link (same as option `-r').
  266.  
  267. `-lARCHIVE'
  268. `--library=ARCHIVE'
  269.      Add archive file ARCHIVE to the list of files to link.  This
  270.      option may be used any number of times.  `ld' will search its
  271.      path-list for occurrences of `libARCHIVE.a' for every ARCHIVE
  272.      specified.  File extensions other than `.a' may be used on certain
  273.      systems.
  274.  
  275. `-LSEARCHDIR'
  276. `--library-path=SEARCHDIR'
  277.      Add path SEARCHDIR to the list of paths that `ld' will search for
  278.      archive libraries and `ld' control scripts.  You may use this
  279.      option any number of times.  The directories are searched in the
  280.      order in which they are specified on the command line.
  281.      Directories specified on the command line are searched before the
  282.      default directories.  All `-L' options apply to all `-l' options,
  283.      regardless of the order in which the options appear.
  284.  
  285.      The default set of paths searched (without being specified with
  286.      `-L') depends on which emulation mode `ld' is using, and in some
  287.      cases also on how it was configured.  *Note Environment::.
  288.  
  289.      The paths can also be specified in a link script with the
  290.      `SEARCH_DIR' command.  Directories specified this way are searched
  291.      at the point in which the linker script appears in the command
  292.      line.
  293.  
  294. `-mEMULATION'
  295.      Emulate the EMULATION linker.  You can list the available
  296.      emulations with the `--verbose' or `-V' options.  The default
  297.      depends on how your `ld' was configured.
  298.  
  299. `-M'
  300. `--print-map'
  301.      Print (to the standard output) a link map--diagnostic information
  302.      about where symbols are mapped by `ld', and information on global
  303.      common storage allocation.
  304.  
  305. `-n'
  306. `--nmagic'
  307.      Set the text segment to be read only, and mark the output as
  308.      `NMAGIC' if possible.
  309.  
  310. `-N'
  311. `--omagic'
  312.      Set the text and data sections to be readable and writable.  Also,
  313.      do not page-align the data segment.  If the output format supports
  314.      Unix style magic numbers, mark the output as `OMAGIC'.
  315.  
  316. `-o OUTPUT'
  317. `--output=OUTPUT'
  318.      Use OUTPUT as the name for the program produced by `ld'; if this
  319.      option is not specified, the name `a.out' is used by default.  The
  320.      script command `OUTPUT' can also specify the output file name.
  321.  
  322. `-r'
  323. `--relocateable'
  324.      Generate relocatable output--i.e., generate an output file that
  325.      can in turn serve as input to `ld'.  This is often called "partial
  326.      linking".  As a side effect, in environments that support standard
  327.      Unix magic numbers, this option also sets the output file's magic
  328.      number to `OMAGIC'.  If this option is not specified, an absolute
  329.      file is produced.  When linking C++ programs, this option *will
  330.      not* resolve references to constructors; to do that, use `-Ur'.
  331.  
  332.      This option does the same thing as `-i'.
  333.  
  334. `-R FILENAME'
  335. `--just-symbols=FILENAME'
  336.      Read symbol names and their addresses from FILENAME, but do not
  337.      relocate it or include it in the output.  This allows your output
  338.      file to refer symbolically to absolute locations of memory defined
  339.      in other programs.  You may use this option more than once.
  340.  
  341.      For compatibility with other ELF linkers, if the `-R' option is
  342.      followed by a directory name, rather than a file name, it is
  343.      treated as the `-rpath' option.
  344.  
  345. `-s'
  346. `--strip-all'
  347.      Omit all symbol information from the output file.
  348.  
  349. `-S'
  350. `--strip-debug'
  351.      Omit debugger symbol information (but not all symbols) from the
  352.      output file.
  353.  
  354. `-t'
  355. `--trace'
  356.      Print the names of the input files as `ld' processes them.
  357.  
  358. `-T COMMANDFILE'
  359. `--script=COMMANDFILE'
  360.      Read link commands from the file COMMANDFILE.  These commands
  361.      replace `ld''s default link script (rather than adding to it), so
  362.      COMMANDFILE must specify everything necessary to describe the
  363.      target format.  *Note Commands::.  If COMMANDFILE does not exist,
  364.      `ld' looks for it in the directories specified by any preceding
  365.      `-L' options.  Multiple `-T' options accumulate.
  366.  
  367. `-u SYMBOL'
  368. `--undefined=SYMBOL'
  369.      Force SYMBOL to be entered in the output file as an undefined
  370.      symbol.  Doing this may, for example, trigger linking of
  371.      additional modules from standard libraries.  `-u' may be repeated
  372.      with different option arguments to enter additional undefined
  373.      symbols.
  374.  
  375. `-v'
  376. `--version'
  377. `-V'
  378.      Display the version number for `ld'.  The `-V' option also lists
  379.      the supported emulations.
  380.  
  381. `-x'
  382. `--discard-all'
  383.      Delete all local symbols.
  384.  
  385. `-X'
  386. `--discard-locals'
  387.      Delete all temporary local symbols.  For most targets, this is all
  388.      local symbols whose names begin with `L'.
  389.  
  390. `-y SYMBOL'
  391. `--trace-symbol=SYMBOL'
  392.      Print the name of each linked file in which SYMBOL appears.  This
  393.      option may be given any number of times.  On many systems it is
  394.      necessary to prepend an underscore.
  395.  
  396.      This option is useful when you have an undefined symbol in your
  397.      link but don't know where the reference is coming from.
  398.  
  399. `-Y PATH'
  400.      Add PATH to the default library search path.  This option exists
  401.      for Solaris compatibility.
  402.  
  403. `-z KEYWORD'
  404.      This option is ignored for Solaris compatibility.
  405.  
  406. `-( ARCHIVES -)'
  407. `--start-group ARCHIVES --end-group'
  408.      The ARCHIVES should be a list of archive files.  They may be
  409.      either explicit file names, or `-l' options.
  410.  
  411.      The specified archives are searched repeatedly until no new
  412.      undefined references are created.  Normally, an archive is
  413.      searched only once in the order that it is specified on the
  414.      command line.  If a symbol in that archive is needed to resolve an
  415.      undefined symbol referred to by an object in an archive that
  416.      appears later on the command line, the linker would not be able to
  417.      resolve that reference.  By grouping the archives, they all be
  418.      searched repeatedly until all possible references are resolved.
  419.  
  420.      Using this option has a significant performance cost.  It is best
  421.      to use it only when there are unavoidable circular references
  422.      between two or more archives.
  423.  
  424. `-assert KEYWORD'
  425.      This option is ignored for SunOS compatibility.
  426.  
  427. `-Bdynamic'
  428. `-dy'
  429. `-call_shared'
  430.      Link against dynamic libraries.  This is only meaningful on
  431.      platforms for which shared libraries are supported.  This option
  432.      is normally the default on such platforms.  The different variants
  433.      of this option are for compatibility with various systems.  You
  434.      may use this option multiple times on the command line: it affects
  435.      library searching for `-l' options which follow it.
  436.  
  437. `-Bstatic'
  438. `-dn'
  439. `-non_shared'
  440. `-static'
  441.      Do not link against shared libraries.  This is only meaningful on
  442.      platforms for which shared libraries are supported.  The different
  443.      variants of this option are for compatibility with various
  444.      systems.  You may use this option multiple times on the command
  445.      line: it affects library searching for `-l' options which follow
  446.      it.
  447.  
  448. `-Bsymbolic'
  449.      When creating a shared library, bind references to global symbols
  450.      to the definition within the shared library, if any.  Normally, it
  451.      is possible for a program linked against a shared library to
  452.      override the definition within the shared library.  This option is
  453.      only meaningful on ELF platforms which support shared libraries.
  454.  
  455. `--cref'
  456.      Output a cross reference table.  If a linker map file is being
  457.      generated, the cross reference table is printed to the map file.
  458.      Otherwise, it is printed on the standard output.
  459.  
  460.      The format of the table is intentionally simple, so that it may be
  461.      easily processed by a script if necessary.  The symbols are
  462.      printed out, sorted by name.  For each symbol, a list of file
  463.      names is given.  If the symbol is defined, the first file listed
  464.      is the location of the definition.  The remaining files contain
  465.      references to the symbol.
  466.  
  467. `--defsym SYMBOL=EXPRESSION'
  468.      Create a global symbol in the output file, containing the absolute
  469.      address given by EXPRESSION.  You may use this option as many
  470.      times as necessary to define multiple symbols in the command line.
  471.      A limited form of arithmetic is supported for the EXPRESSION in
  472.      this context: you may give a hexadecimal constant or the name of
  473.      an existing symbol, or use `+' and `-' to add or subtract
  474.      hexadecimal constants or symbols.  If you need more elaborate
  475.      expressions, consider using the linker command language from a
  476.      script (*note Assignment: Symbol Definitions: Assignment.).
  477.      *Note:*  there should be no white space between SYMBOL, the equals
  478.      sign ("="), and EXPRESSION.
  479.  
  480. `--dynamic-linker FILE'
  481.      Set the name of the dynamic linker.  This is only meaningful when
  482.      generating dynamically linked ELF executables.  The default dynamic
  483.      linker is normally correct; don't use this unless you know what
  484.      you are doing.
  485.  
  486. `-EB'
  487.      Link big-endian objects.  This affects the default output format.
  488.  
  489. `-EL'
  490.      Link little-endian objects.  This affects the default output
  491.      format.
  492.  
  493. `-embedded-relocs'
  494.      This option is only meaningful when linking MIPS embedded PIC code,
  495.      generated by the -membedded-pic option to the GNU compiler and
  496.      assembler.  It causes the linker to create a table which may be
  497.      used at runtime to relocate any data which was statically
  498.      initialized to pointer values.  See the code in testsuite/ld-empic
  499.      for details.
  500.  
  501. `--help'
  502.      Print a summary of the command-line options on the standard output
  503.      and exit.
  504.  
  505. `-Map MAPFILE'
  506.      Print to the file MAPFILE a link map--diagnostic information about
  507.      where symbols are mapped by `ld', and information on global common
  508.      storage allocation.
  509.  
  510. `--no-keep-memory'
  511.      `ld' normally optimizes for speed over memory usage by caching the
  512.      symbol tables of input files in memory.  This option tells `ld' to
  513.      instead optimize for memory usage, by rereading the symbol tables
  514.      as necessary.  This may be required if `ld' runs out of memory
  515.      space while linking a large executable.
  516.  
  517. `--no-whole-archive'
  518.      Turn off the effect of the `--whole-archive' option for subsequent
  519.      archive files.
  520.  
  521. `--noinhibit-exec'
  522.      Retain the executable output file whenever it is still usable.
  523.      Normally, the linker will not produce an output file if it
  524.      encounters errors during the link process; it exits without
  525.      writing an output file when it issues any error whatsoever.
  526.  
  527. `-oformat OUTPUT-FORMAT'
  528.      `ld' may be configured to support more than one kind of object
  529.      file.  If your `ld' is configured this way, you can use the
  530.      `-oformat' option to specify the binary format for the output
  531.      object file.  Even when `ld' is configured to support alternative
  532.      object formats, you don't usually need to specify this, as `ld'
  533.      should be configured to produce as a default output format the most
  534.      usual format on each machine.  OUTPUT-FORMAT is a text string, the
  535.      name of a particular format supported by the BFD libraries.  (You
  536.      can list the available binary formats with `objdump -i'.)  The
  537.      script command `OUTPUT_FORMAT' can also specify the output format,
  538.      but this option overrides it.  *Note BFD::.
  539.  
  540. `-qmagic'
  541.      This option is ignored for Linux compatibility.
  542.  
  543. `-Qy'
  544.      This option is ignored for SVR4 compatibility.
  545.  
  546. `--relax'
  547.      An option with machine dependent effects.  This option is only
  548.      supported on a few targets.  *Note `ld' and the H8/300: H8/300.
  549.      *Note `ld' and the Intel 960 family: i960.
  550.  
  551.      On some platforms, the `--relax' option performs global
  552.      optimizations that become possible when the linker resolves
  553.      addressing in the program, such as relaxing address modes and
  554.      synthesizing new instructions in the output object file.
  555.  
  556.      On platforms where this is not supported, `-relax' is accepted, but
  557.      ignored.
  558.  
  559. `--retain-symbols-file FILENAME'
  560.      Retain *only* the symbols listed in the file FILENAME, discarding
  561.      all others.  FILENAME is simply a flat file, with one symbol name
  562.      per line.  This option is especially useful in environments (such
  563.      as VxWorks) where a large global symbol table is accumulated
  564.      gradually, to conserve run-time memory.
  565.  
  566.      `-retain-symbols-file' does *not* discard undefined symbols, or
  567.      symbols needed for relocations.
  568.  
  569.      You may only specify `-retain-symbols-file' once in the command
  570.      line.  It overrides `-s' and `-S'.
  571.  
  572. `-rpath DIR'
  573.      Add a directory to the runtime library search path.  This is used
  574.      when linking an ELF executable with shared objects.  All `-rpath'
  575.      arguments are concatenated and passed to the runtime linker, which
  576.      uses them to locate shared objects at runtime.  The `-rpath'
  577.      option is also used when locating shared objects which are needed
  578.      by shared objects explicitly included in the link; see the
  579.      description of the `-rpath-link' option.  If `-rpath' is not used
  580.      when linking an ELF executable, the contents of the environment
  581.      variable `LD_RUN_PATH' will be used if it is defined.
  582.  
  583.      The `-rpath' option may also be used on SunOS.  By default, on
  584.      SunOS, the linker will form a runtime search patch out of all the
  585.      `-L' options it is given.  If a `-rpath' option is used, the
  586.      runtime search path will be formed exclusively using the `-rpath'
  587.      options, ignoring the `-L' options.  This can be useful when using
  588.      gcc, which adds many `-L' options which may be on NFS mounted
  589.      filesystems.
  590.  
  591.      For compatibility with other ELF linkers, if the `-R' option is
  592.      followed by a directory name, rather than a file name, it is
  593.      treated as the `-rpath' option.
  594.  
  595. `-rpath-link DIR'
  596.      When using ELF or SunOS, one shared library may require another.
  597.      This happens when an `ld -shared' link includes a shared library
  598.      as one of the input files.
  599.  
  600.      When the linker encounters such a dependency when doing a
  601.      non-shared, non-relocateable link, it will automatically try to
  602.      locate the required shared library and include it in the link, if
  603.      it is not included explicitly.  In such a case, the `-rpath-link'
  604.      option specifies the first set of directories to search.  The
  605.      `-rpath-link' option may specify a sequence of directory names
  606.      either by specifying a list of names separated by colons, or by
  607.      appearing multiple times.
  608.  
  609.      The linker uses the following search paths to locate required
  610.      shared libraries.
  611.        1. Any directories specified by `-rpath-link' options.
  612.  
  613.        2. Any directories specified by `-rpath' options.  The difference
  614.           between `-rpath' and `-rpath-link' is that directories
  615.           specified by `-rpath' options are included in the executable
  616.           and used at runtime, whereas the `-rpath-link' option is only
  617.           effective at link time.
  618.  
  619.        3. On an ELF system, if the `-rpath' and `rpath-link' options
  620.           were not used, search the contents of the environment variable
  621.           `LD_RUN_PATH'.
  622.  
  623.        4. On SunOS, if the `-rpath' option was not used, search any
  624.           directories specified using `-L' options.
  625.  
  626.        5. For a native linker, the contents of the environment variable
  627.           `LD_LIBRARY_PATH'.
  628.  
  629.        6. The default directories, normally `/lib' and `/usr/lib'.
  630.  
  631.      If the required shared library is not found, the linker will issue
  632.      a warning and continue with the link.
  633.  
  634. `-shared'
  635. `-Bshareable'
  636.      Create a shared library.  This is currently only supported on ELF,
  637.      XCOFF and SunOS platforms.  On SunOS, the linker will
  638.      automatically create a shared library if the `-e' option is not
  639.      used and there are undefined symbols in the link.
  640.  
  641. `--sort-common'
  642.      This option tells `ld' to sort the common symbols by size when it
  643.      places them in the appropriate output sections.  First come all
  644.      the one byte symbols, then all the two bytes, then all the four
  645.      bytes, and then everything else.  This is to prevent gaps between
  646.      symbols due to alignment constraints.
  647.  
  648. `--split-by-file'
  649.      Similar to `--split-by-reloc' but creates a new output section for
  650.      each input file.
  651.  
  652. `--split-by-reloc COUNT'
  653.      Trys to creates extra sections in the output file so that no single
  654.      output section in the file contains more than COUNT relocations.
  655.      This is useful when generating huge relocatable for downloading
  656.      into certain real time kernels with the COFF object file format;
  657.      since COFF cannot represent more than 65535 relocations in a
  658.      single section.  Note that this will fail to work with object file
  659.      formats which do not support arbitrary sections.  The linker will
  660.      not split up individual input sections for redistribution, so if a
  661.      single input section contains more than COUNT relocations one
  662.      output section will contain that many relocations.
  663.  
  664. `--stats'
  665.      Compute and display statistics about the operation of the linker,
  666.      such as execution time and memory usage.
  667.  
  668. `-traditional-format'
  669.      For some targets, the output of `ld' is different in some ways from
  670.      the output of some existing linker.  This switch requests `ld' to
  671.      use the traditional format instead.
  672.  
  673.      For example, on SunOS, `ld' combines duplicate entries in the
  674.      symbol string table.  This can reduce the size of an output file
  675.      with full debugging information by over 30 percent.
  676.      Unfortunately, the SunOS `dbx' program can not read the resulting
  677.      program (`gdb' has no trouble).  The `-traditional-format' switch
  678.      tells `ld' to not combine duplicate entries.
  679.  
  680. `-Tbss ORG'
  681. `-Tdata ORG'
  682. `-Ttext ORG'
  683.      Use ORG as the starting address for--respectively--the `bss',
  684.      `data', or the `text' segment of the output file.  ORG must be a
  685.      single hexadecimal integer; for compatibility with other linkers,
  686.      you may omit the leading `0x' usually associated with hexadecimal
  687.      values.
  688.  
  689. `-Ur'
  690.      For anything other than C++ programs, this option is equivalent to
  691.      `-r': it generates relocatable output--i.e., an output file that
  692.      can in turn serve as input to `ld'.  When linking C++ programs,
  693.      `-Ur' *does* resolve references to constructors, unlike `-r'.  It
  694.      does not work to use `-Ur' on files that were themselves linked
  695.      with `-Ur'; once the constructor table has been built, it cannot
  696.      be added to.  Use `-Ur' only for the last partial link, and `-r'
  697.      for the others.
  698.  
  699. `--verbose'
  700.      Display the version number for `ld' and list the linker emulations
  701.      supported.  Display which input files can and cannot be opened.
  702.      Display the linker script if using a default builtin script.
  703.  
  704. `-warn-common'
  705.      Warn when a common symbol is combined with another common symbol
  706.      or with a symbol definition.  Unix linkers allow this somewhat
  707.      sloppy practice, but linkers on some other operating systems do
  708.      not.  This option allows you to find potential problems from
  709.      combining global symbols.  Unfortunately, some C libraries use
  710.      this practice, so you may get some warnings about symbols in the
  711.      libraries as well as in your programs.
  712.  
  713.      There are three kinds of global symbols, illustrated here by C
  714.      examples:
  715.  
  716.     `int i = 1;'
  717.           A definition, which goes in the initialized data section of
  718.           the output file.
  719.  
  720.     `extern int i;'
  721.           An undefined reference, which does not allocate space.  There
  722.           must be either a definition or a common symbol for the
  723.           variable somewhere.
  724.  
  725.     `int i;'
  726.           A common symbol.  If there are only (one or more) common
  727.           symbols for a variable, it goes in the uninitialized data
  728.           area of the output file.  The linker merges multiple common
  729.           symbols for the same variable into a single symbol.  If they
  730.           are of different sizes, it picks the largest size.  The
  731.           linker turns a common symbol into a declaration, if there is
  732.           a definition of the same variable.
  733.  
  734.      The `-warn-common' option can produce five kinds of warnings.  Each
  735.      warning consists of a pair of lines: the first describes the
  736.      symbol just encountered, and the second describes the previous
  737.      symbol encountered with the same name.  One or both of the two
  738.      symbols will be a common symbol.
  739.  
  740.        1. Turning a common symbol into a reference, because there is
  741.           already a definition for the symbol.
  742.                FILE(SECTION): warning: common of `SYMBOL'
  743.                   overridden by definition
  744.                FILE(SECTION): warning: defined here
  745.  
  746.        2. Turning a common symbol into a reference, because a later
  747.           definition for the symbol is encountered.  This is the same
  748.           as the previous case, except that the symbols are encountered
  749.           in a different order.
  750.                FILE(SECTION): warning: definition of `SYMBOL'
  751.                   overriding common
  752.                FILE(SECTION): warning: common is here
  753.  
  754.        3. Merging a common symbol with a previous same-sized common
  755.           symbol.
  756.                FILE(SECTION): warning: multiple common
  757.                   of `SYMBOL'
  758.                FILE(SECTION): warning: previous common is here
  759.  
  760.        4. Merging a common symbol with a previous larger common symbol.
  761.                FILE(SECTION): warning: common of `SYMBOL'
  762.                   overridden by larger common
  763.                FILE(SECTION): warning: larger common is here
  764.  
  765.        5. Merging a common symbol with a previous smaller common
  766.           symbol.  This is the same as the previous case, except that
  767.           the symbols are encountered in a different order.
  768.                FILE(SECTION): warning: common of `SYMBOL'
  769.                   overriding smaller common
  770.                FILE(SECTION): warning: smaller common is here
  771.  
  772. `-warn-constructors'
  773.      Warn if any global constructors are used.  This is only useful for
  774.      a few object file formats.  For formats like COFF or ELF, the
  775.      linker can not detect the use of global constructors.
  776.  
  777. `-warn-multiple-gp'
  778.      Warn if multiple global pointer values are required in the output
  779.      file.  This is only meaningful for certain processors, such as the
  780.      Alpha.  Specifically, some processors put large-valued constants
  781.      in a special section.  A special register (the global pointer)
  782.      points into the middle of this section, so that constants can be
  783.      loaded efficiently via a base-register relative addressing mode.
  784.      Since the offset in base-register relative mode is fixed and
  785.      relatively small (e.g., 16 bits), this limits the maximum size of
  786.      the constant pool.  Thus, in large programs, it is often necessary
  787.      to use multiple global pointer values in order to be able to
  788.      address all possible constants.  This option causes a warning to
  789.      be issued whenever this case occurs.
  790.  
  791. `-warn-once'
  792.      Only warn once for each undefined symbol, rather than once per
  793.      module which refers to it.
  794.  
  795. `--whole-archive'
  796.      For each archive mentioned on the command line after the
  797.      `--whole-archive' option, include every object file in the archive
  798.      in the link, rather than searching the archive for the required
  799.      object files.  This is normally used to turn an archive file into
  800.      a shared library, forcing every object to be included in the
  801.      resulting shared library.  This option may be used more than once.
  802.  
  803. `--wrap SYMBOL'
  804.      Use a wrapper function for SYMBOL.  Any undefined reference to
  805.      SYMBOL will be resolved to `__wrap_SYMBOL'.  Any undefined
  806.      reference to `__real_SYMBOL' will be resolved to SYMBOL.
  807.  
  808.      This can be used to provide a wrapper for a system function.  The
  809.      wrapper function should be called `__wrap_SYMBOL'.  If it wishes
  810.      to call the system function, it should call `__real_SYMBOL'.
  811.  
  812.      Here is a trivial example:
  813.  
  814.           void *
  815.           __wrap_malloc (int c)
  816.           {
  817.             printf ("malloc called with %ld\n", c);
  818.             return __real_malloc (c);
  819.           }
  820.  
  821.      If you link other code with this file using `--wrap malloc', then
  822.      all calls to `malloc' will call the function `__wrap_malloc'
  823.      instead.  The call to `__real_malloc' in `__wrap_malloc' will call
  824.      the real `malloc' function.
  825.  
  826.      You may wish to provide a `__real_malloc' function as well, so that
  827.      links without the `--wrap' option will succeed.  If you do this,
  828.      you should not put the definition of `__real_malloc' in the same
  829.      file as `__wrap_malloc'; if you do, the assembler may resolve the
  830.      call before the linker has a chance to wrap it to `malloc'.
  831.  
  832. 
  833. File: ld.info,  Node: Environment,  Prev: Options,  Up: Invocation
  834.  
  835. Environment Variables
  836. =====================
  837.  
  838.    You can change the behavior of `ld' with the environment variable
  839. `GNUTARGET'.
  840.  
  841.    `GNUTARGET' determines the input-file object format if you don't use
  842. `-b' (or its synonym `-format').  Its value should be one of the BFD
  843. names for an input format (*note BFD::.).  If there is no `GNUTARGET'
  844. in the environment, `ld' uses the natural format of the target. If
  845. `GNUTARGET' is set to `default' then BFD attempts to discover the input
  846. format by examining binary input files; this method often succeeds, but
  847. there are potential ambiguities, since there is no method of ensuring
  848. that the magic number used to specify object-file formats is unique.
  849. However, the configuration procedure for BFD on each system places the
  850. conventional format for that system first in the search-list, so
  851. ambiguities are resolved in favor of convention.
  852.  
  853. 
  854. File: ld.info,  Node: Commands,  Next: Machine Dependent,  Prev: Invocation,  Up: Top
  855.  
  856. Command Language
  857. ****************
  858.  
  859.    The command language provides explicit control over the link process,
  860. allowing complete specification of the mapping between the linker's
  861. input files and its output.  It controls:
  862.    * input files
  863.  
  864.    * file formats
  865.  
  866.    * output file layout
  867.  
  868.    * addresses of sections
  869.  
  870.    * placement of common blocks
  871.  
  872.    You may supply a command file (also known as a link script) to the
  873. linker either explicitly through the `-T' option, or implicitly as an
  874. ordinary file. If the linker opens a file which it cannot recognize as
  875. a supported object or archive format, it reports an error.
  876.  
  877. * Menu:
  878.  
  879. * Scripts::                     Linker Scripts
  880. * Expressions::                 Expressions
  881. * MEMORY::                      MEMORY Command
  882. * SECTIONS::                    SECTIONS Command
  883. * PHDRS::            PHDRS Command
  884. * Entry Point::                 The Entry Point
  885. * Option Commands::             Option Commands
  886.  
  887. 
  888. File: ld.info,  Node: Scripts,  Next: Expressions,  Up: Commands
  889.  
  890. Linker Scripts
  891. ==============
  892.  
  893.    The `ld' command language is a collection of statements; some are
  894. simple keywords setting a particular option, some are used to select and
  895. group input files or name output files; and two statement types have a
  896. fundamental and pervasive impact on the linking process.
  897.  
  898.    The most fundamental command of the `ld' command language is the
  899. `SECTIONS' command (*note SECTIONS::.).  Every meaningful command
  900. script must have a `SECTIONS' command: it specifies a "picture" of the
  901. output file's layout, in varying degrees of detail.  No other command
  902. is required in all cases.
  903.  
  904.    The `MEMORY' command complements `SECTIONS' by describing the
  905. available memory in the target architecture.  This command is optional;
  906. if you don't use a `MEMORY' command, `ld' assumes sufficient memory is
  907. available in a contiguous block for all output.  *Note MEMORY::.
  908.  
  909.    You may include comments in linker scripts just as in C: delimited
  910. by `/*' and `*/'.  As in C, comments are syntactically equivalent to
  911. whitespace.
  912.  
  913. 
  914. File: ld.info,  Node: Expressions,  Next: MEMORY,  Prev: Scripts,  Up: Commands
  915.  
  916. Expressions
  917. ===========
  918.  
  919.    Many useful commands involve arithmetic expressions.  The syntax for
  920. expressions in the command language is identical to that of C
  921. expressions, with the following features:
  922.    * All expressions evaluated as integers and are of "long" or
  923.      "unsigned long" type.
  924.  
  925.    * All constants are integers.
  926.  
  927.    * All of the C arithmetic operators are provided.
  928.  
  929.    * You may reference, define, and create global variables.
  930.  
  931.    * You may call special purpose built-in functions.
  932.  
  933. * Menu:
  934.  
  935. * Integers::                    Integers
  936. * Symbols::                     Symbol Names
  937. * Location Counter::            The Location Counter
  938. * Operators::                   Operators
  939. * Evaluation::                  Evaluation
  940. * Assignment::                  Assignment: Defining Symbols
  941. * Arithmetic Functions::        Built-In Functions
  942. * Semicolons::                  Semicolon Usage
  943.  
  944. 
  945. File: ld.info,  Node: Integers,  Next: Symbols,  Up: Expressions
  946.  
  947. Integers
  948. --------
  949.  
  950.    An octal integer is `0' followed by zero or more of the octal digits
  951. (`01234567').
  952.      _as_octal = 0157255;
  953.  
  954.    A decimal integer starts with a non-zero digit followed by zero or
  955. more digits (`0123456789').
  956.      _as_decimal = 57005;
  957.  
  958.    A hexadecimal integer is `0x' or `0X' followed by one or more
  959. hexadecimal digits chosen from `0123456789abcdefABCDEF'.
  960.      _as_hex = 0xdead;
  961.  
  962.    To write a negative integer, use the prefix operator `-' (*note
  963. Operators::.).
  964.      _as_neg = -57005;
  965.  
  966.    Additionally the suffixes `K' and `M' may be used to scale a
  967. constant by `1024' or `1024*1024' respectively. For example, the
  968. following all refer to the same quantity:
  969.  
  970.              _fourk_1 = 4K;
  971.              _fourk_2 = 4096;
  972.              _fourk_3 = 0x1000;
  973.  
  974. 
  975. File: ld.info,  Node: Symbols,  Next: Location Counter,  Prev: Integers,  Up: Expressions
  976.  
  977. Symbol Names
  978. ------------
  979.  
  980.    Unless quoted, symbol names start with a letter, underscore, or point
  981. and may include any letters, underscores, digits, points, and hyphens.
  982. Unquoted symbol names must not conflict with any keywords.  You can
  983. specify a symbol which contains odd characters or has the same name as
  984. a keyword, by surrounding the symbol name in double quotes:
  985.              "SECTION" = 9;
  986.              "with a space" = "also with a space" + 10;
  987.  
  988.    Since symbols can contain many non-alphabetic characters, it is
  989. safest to delimit symbols with spaces.  For example, `A-B' is one
  990. symbol, whereas `A - B' is an expression involving subtraction.
  991.  
  992. 
  993. File: ld.info,  Node: Location Counter,  Next: Operators,  Prev: Symbols,  Up: Expressions
  994.  
  995. The Location Counter
  996. --------------------
  997.  
  998.    The special linker variable "dot" `.' always contains the current
  999. output location counter. Since the `.' always refers to a location in
  1000. an output section, it must always appear in an expression within a
  1001. `SECTIONS' command. The `.' symbol may appear anywhere that an ordinary
  1002. symbol is allowed in an expression, but its assignments have a side
  1003. effect. Assigning a value to the `.' symbol will cause the location
  1004. counter to be moved.  This may be used to create holes in the output
  1005. section.  The location counter may never be moved backwards.
  1006.      SECTIONS
  1007.      {
  1008.        output :
  1009.        {
  1010.        file1(.text)
  1011.        . = . + 1000;
  1012.        file2(.text)
  1013.        . += 1000;
  1014.        file3(.text)
  1015.        } = 0x1234;
  1016.      }
  1017.  
  1018. In the previous example, `file1' is located at the beginning of the
  1019. output section, then there is a 1000 byte gap.  Then `file2' appears,
  1020. also with a 1000 byte gap following before `file3' is loaded.  The
  1021. notation `= 0x1234' specifies what data to write in the gaps (*note
  1022. Section Options::.).
  1023.  
  1024. 
  1025. File: ld.info,  Node: Operators,  Next: Evaluation,  Prev: Location Counter,  Up: Expressions
  1026.  
  1027. Operators
  1028. ---------
  1029.  
  1030.    The linker recognizes  the standard C set of arithmetic operators,
  1031. with the standard bindings and precedence levels:
  1032.      precedence      associativity   Operators                Notes
  1033.      (highest)
  1034.      1               left            !  -  ~                  (1)
  1035.      2               left            *  /  %
  1036.      3               left            +  -
  1037.      4               left            >>  <<
  1038.      5               left            ==  !=  >  <  <=  >=
  1039.      6               left            &
  1040.      7               left            |
  1041.      8               left            &&
  1042.      9               left            ||
  1043.      10              right           ? :
  1044.      11              right           &=  +=  -=  *=  /=       (2)
  1045.      (lowest)
  1046.    Notes: (1) Prefix operators (2) *Note Assignment::.
  1047.  
  1048. 
  1049. File: ld.info,  Node: Evaluation,  Next: Assignment,  Prev: Operators,  Up: Expressions
  1050.  
  1051. Evaluation
  1052. ----------
  1053.  
  1054.    The linker uses "lazy evaluation" for expressions; it only calculates
  1055. an expression when absolutely necessary.  The linker needs the value of
  1056. the start address, and the lengths of memory regions, in order to do any
  1057. linking at all; these values are computed as soon as possible when the
  1058. linker reads in the command file.  However, other values (such as symbol
  1059. values) are not known or needed until after storage allocation.  Such
  1060. values are evaluated later, when other information (such as the sizes of
  1061. output sections) is available for use in the symbol assignment
  1062. expression.
  1063.  
  1064. 
  1065. File: ld.info,  Node: Assignment,  Next: Arithmetic Functions,  Prev: Evaluation,  Up: Expressions
  1066.  
  1067. Assignment: Defining Symbols
  1068. ----------------------------
  1069.  
  1070.    You may create global symbols, and assign values (addresses) to
  1071. global symbols, using any of the C assignment operators:
  1072.  
  1073. `SYMBOL  = EXPRESSION ;'
  1074. `SYMBOL &= EXPRESSION ;'
  1075. `SYMBOL += EXPRESSION ;'
  1076. `SYMBOL -= EXPRESSION ;'
  1077. `SYMBOL *= EXPRESSION ;'
  1078. `SYMBOL /= EXPRESSION ;'
  1079.    Two things distinguish assignment from other operators in `ld'
  1080. expressions.
  1081.    * Assignment may only be used at the root of an expression; `a=b+3;'
  1082.      is allowed, but `a+b=3;' is an error.
  1083.  
  1084.    * You must place a trailing semicolon (";") at the end of an
  1085.      assignment statement.
  1086.  
  1087.    Assignment statements may appear:
  1088.    * as commands in their own right in an `ld' script; or
  1089.  
  1090.    * as independent statements within a `SECTIONS' command; or
  1091.  
  1092.    * as part of the contents of a section definition in a `SECTIONS'
  1093.      command.
  1094.  
  1095.    The first two cases are equivalent in effect--both define a symbol
  1096. with an absolute address.  The last case defines a symbol whose address
  1097. is relative to a particular section (*note SECTIONS::.).
  1098.  
  1099.    When a linker expression is evaluated and assigned to a variable, it
  1100. is given either an absolute or a relocatable type. An absolute
  1101. expression type is one in which the symbol contains the value that it
  1102. will have in the output file; a relocatable expression type is one in
  1103. which the value is expressed as a fixed offset from the base of a
  1104. section.
  1105.  
  1106.    The type of the expression is controlled by its position in the
  1107. script file.  A symbol assigned within a section definition is created
  1108. relative to the base of the section; a symbol assigned in any other
  1109. place is created as an absolute symbol. Since a symbol created within a
  1110. section definition is relative to the base of the section, it will
  1111. remain relocatable if relocatable output is requested.  A symbol may be
  1112. created with an absolute value even when assigned to within a section
  1113. definition by using the absolute assignment function `ABSOLUTE'.  For
  1114. example, to create an absolute symbol whose address is the last byte of
  1115. an output section named `.data':
  1116.      SECTIONS{ ...
  1117.        .data :
  1118.          {
  1119.            *(.data)
  1120.            _edata = ABSOLUTE(.) ;
  1121.          }
  1122.      ... }
  1123.  
  1124.    The linker tries to put off the evaluation of an assignment until all
  1125. the terms in the source expression are known (*note Evaluation::.).  For
  1126. instance, the sizes of sections cannot be known until after allocation,
  1127. so assignments dependent upon these are not performed until after
  1128. allocation. Some expressions, such as those depending upon the location
  1129. counter "dot", `.' must be evaluated during allocation. If the result
  1130. of an expression is required, but the value is not available, then an
  1131. error results.  For example, a script like the following
  1132.      SECTIONS { ...
  1133.        text 9+this_isnt_constant :
  1134.          { ...
  1135.          }
  1136.      ... }
  1137.  
  1138. will cause the error message "`Non constant expression for initial
  1139. address'".
  1140.  
  1141.    In some cases, it is desirable for a linker script to define a symbol
  1142. only if it is referenced, and only if it is not defined by any object
  1143. included in the link.  For example, traditional linkers defined the
  1144. symbol `etext'.  However, ANSI C requires that the user be able to use
  1145. `etext' as a function name without encountering an error.  The
  1146. `PROVIDE' keyword may be used to define a symbol, such as `etext', only
  1147. if it is referenced but not defined.  The syntax is `PROVIDE(SYMBOL =
  1148. EXPRESSION)'.
  1149.  
  1150.